//
// Created by lau on 2019-10-17.
//

#ifndef VIDEOEFFECT_PROGRAM_H
#define VIDEOEFFECT_PROGRAM_H

//#include <stdlib.h>
#include <iostream>
#include <map>
#include <GLES2/gl2.h>

namespace VideoEffect {
    class Program {

    public:
        typedef std::map<std::string, GLint> handle_map_type;
        GLuint mProgramID = -1;

    private:
        handle_map_type mShaderHandleMap;

    public:
        void init(const char *vsSource, const char *fsSource);

        void use();

        void setUniformInt(const std::string &name, GLint value);

        void setUniformFloat(const std::string &name, GLfloat value);

        void setUniformTexture(const std::string &name, GLint x, GLuint textureID, GLenum target);

        void setVertexAttribPointer(const std::string &name, GLint size, GLenum type, GLboolean normalized, GLsizei stride, void *ptr);

        void disableVertexAttrib(const std::string &name);

    private:

        GLint getHandle(const std::string &basicString);

        bool compileShader(GLuint *shader, GLenum type, const char *source);

        bool linkProgram(GLuint programId);
    };

}

#endif //VIDEOEFFECT_PROGRAM_H
